package com.xxxy.controller;

import com.xxxy.commonResult.CommonResult;
import com.xxxy.log.Log;
import com.xxxy.model.KnowledgePoint;
import com.xxxy.response.GradeAnalysisResponse;
import com.xxxy.response.KnowledgePointResponse;
import com.xxxy.service.KnowledgePointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author sjh
 * @date 2022/2/21 16:29
 */
@RestController
@Api(tags = "知识点管理")
@RequestMapping("/knowledgePoint")
public class KnowledgePointController {

    @Autowired
    KnowledgePointService knowledgePointService;

    @Log(module = "知识点管理", description = "获取课程对应知识点列表")
    @GetMapping(value = "/list")
    @ApiOperation(value = "课程对应知识点列表")
    public CommonResult<List<KnowledgePointResponse>> list(@ApiParam("课程id") @RequestParam Integer courseId) {
        return CommonResult.success(knowledgePointService.ListTree(courseId));
    }

    @Log(module = "知识点管理", description = "新增知识点")
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增知识点")
    public CommonResult<Boolean> add(@ApiParam("知识点信息") @RequestBody KnowledgePoint knowledgePoint) {
        boolean flag = knowledgePointService.save(knowledgePoint);
        if (flag) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @Log(module = "知识点管理", description = "删除知识点")
    @DeleteMapping(value = "/delete")
    @ApiOperation(value = "删除知识点")
    public CommonResult<Boolean> delete(@ApiParam("知识点id") @RequestParam Integer knowledgePointId) {
        boolean flag = knowledgePointService.removeById(knowledgePointId);
        if (flag) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @Log(module = "知识点管理", description = "新增知识点")
    @PostMapping(value = "/update")
    @ApiOperation(value = "新增知识点")
    public CommonResult<Boolean> update(@ApiParam("知识点信息") @RequestBody KnowledgePoint knowledgePoint) {
        boolean flag = knowledgePointService.updateById(knowledgePoint);
        if (flag) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @Log(module = "知识点管理", description = "学生考试结果分析")
    @GetMapping(value = "/studentExamAnalysis")
    @ApiOperation(value = "学生考试结果分析")
    public CommonResult<List<GradeAnalysisResponse>> studentExamAnalysis(@ApiParam("课程id") @RequestParam Integer courseId, @ApiParam("试卷id") @RequestParam Integer examId, @ApiParam("学生账号") @RequestParam String studentAccount) {
        return CommonResult.success(knowledgePointService.getStudentGradeAnalysis(courseId, examId, studentAccount));
    }

    @Log(module = "知识点管理", description = "班级或学科考试结果分析")
    @GetMapping(value = "/classOrCourseExamAnalysis")
    @ApiOperation(value = "班级或学科考试结果分析")
    public CommonResult<List<GradeAnalysisResponse>> classExamAnalysis(@ApiParam("课程id") @RequestParam Integer courseId, @ApiParam("试卷id") @RequestParam Integer examId, @ApiParam("教学班id") @RequestParam(required = false) Integer teachingClassId) {
        return CommonResult.success(knowledgePointService.getClassOrCourseGradeAnalysis(courseId, examId, teachingClassId));
    }
}
